<?php
class FaqsSendForm extends sfForm{
	public function configure(){
		$this->setWidgets(array(
				'cate_id'        => new sfWidgetFormDoctrineChoice(array('model' => 'FaqCates', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('FaqCates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at) AND cate_id = 0'),'multiple' => false, 'add_empty' => '---lĩnh vực hỏi đáp---')),
				'full_name'		=> new sfWidgetFormInputText(),
				'email'			=> new sfWidgetFormInputText(),
				'phone_number'	=> new sfWidgetFormInputText(),	
				'location_city_id'        	=> new sfWidgetFormDoctrineChoice(array('model' => 'LocationCities', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationCities b')->orderBy('b.sort_order ASC, b.name ASC'),'multiple' => false, 'add_empty' => '---tỉnh/thành phố---')),
				'location_district_id'      => new sfWidgetFormInputText(),
				'title'			=> new sfWidgetFormInputText(),
				'question'       => new sfWidgetFormTextarea(),
				'captcha'			=> new sfWidgetFormInput()
		));

		$this->setValidators(array(
				'cate_id'        => new sfValidatorDoctrineChoice(array('model' => 'FaqCates', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('FaqCates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'), 'required' => true),array('required'=> 'input cate_id')),
				'full_name'       => new sfValidatorString(array('required' => true),array('required'=> ' Nhập vào họ tên.')),
				'email'       	=> new sfValidatorString(array('required' =>  true),array('required'=> ' Địa chỉ Email chưa chính xác.')),
				'phone_number'       => new sfValidatorString(array('required' => false)),
				'location_city_id'   => new sfValidatorDoctrineChoice(array('model' => 'LocationCities', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationCities b'), 'required' => false),array('required'=> 'input location_city_id')),
				'location_district_id'   => new sfValidatorDoctrineChoice(array('model' => 'LocationDistricts', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationDistricts b'), 'required' => false),array('required'=> 'input location_district_id')),
				'title'       => new sfValidatorString(array('required' => true),array('required'=> ' Nhâp vào tiêu đề câu hỏi của bạn.')),
				'question'       => new sfValidatorString(array('required' => true),array('required'=> ' Nhập vào nội dung câu hỏi của bạn.')),
				'captcha'			=> new sfValidatorString(array('required'=> true),array('required'=> ' Mã bảo vệ chưa chính xác.')),
		));
		parent::configure();

		/*
		 * Setting name of form
		*/
		$this->widgetSchema->setNameFormat('FaqsSend[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
}
